/*
 * Wantmore - Service Delivery Platform.
 *
 * $Id: AlbumDeleteFromController.java 60 2010-10-13 07:26:24Z alexey.batyuta@gmail.com $
 *
 * Copyright 2010 by Sunbay Software Crimea Ltd.
 * All rights reserved
 */
package ua.crimea.bat.ss.forms;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.support.SessionStatus;
import ua.crimea.bat.ss.services.PhotoAlbumsService;

/**
 * User: bat
 * Date: Mar 26, 2010
 * Time: 9:28:09 AM
 */
@Controller("albumDeleteFromController")
@RequestMapping("/albums/{albumId}/delete")
public class AlbumDeleteFromController {
    protected PhotoAlbumsService photoAlbumsService;

    public AlbumDeleteFromController() {
    }

    public void setPhotoAlbumsService(PhotoAlbumsService photoAlbumsService) {
        this.photoAlbumsService = photoAlbumsService;
    }

    public PhotoAlbumsService getPhotoAlbumsService() {
        return photoAlbumsService;
    }

    @InitBinder
    public void setAllowedFields(WebDataBinder dataBinder) {
        dataBinder.setDisallowedFields("id");
    }

    @Autowired
    public AlbumDeleteFromController(PhotoAlbumsService photoAlbumsService) {
        setPhotoAlbumsService(photoAlbumsService);
    }

    @RequestMapping(method = RequestMethod.DELETE)
    public String deleteAlbum(@PathVariable int albumId, SessionStatus status) {
        photoAlbumsService.deleteAlbum(albumId);
        status.setComplete();
        return "redirect:/albums/list";
    }
}